package com.sunny.l55;

import java.util.ArrayList;
import java.util.Stack;

/**
 * @Author zsunny
 * @Date 2018/9/13 10:10
 * @Mail zsunny@yeah.net
 */
public class Solution {
    public ArrayList<Integer> inorderTraversal(TreeNode root) {
        ArrayList<Integer> res = new ArrayList<>();
        if(null == root)
            return res;
        Stack<TreeNode> stack = new Stack<>();
        TreeNode node = root;
        while (null != node){
            stack.push(node);
            node = node.left;
        }
        while (!stack.empty()){
            TreeNode cur = stack.pop();
            res.add(cur.val);
            cur = cur.right;
            while (null != cur){
                stack.push(cur);
                cur = cur.left;
            }
        }
        return res;
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}
